<?php
/**
 *@author Connor <caokang@foxmail.com>
 *@todo
 *@link www.zeevin.com
 */
$friend=$follower=$follow=array();
//分拣好友和关注者
foreach((array)$friends as $k=>$v){
      if($v['status']==3){
            $friend[] =$v;
      }else{
            if(($v['status']==1 && $v[uid]==Yii::app()->user->id)||($v['status']==2 && $v[fid]==Yii::app()->user->id))
                  $follower[] = $v;//我关注的
            else
                  $follow[] = $v;//关注我的
      }
}
?>
<div class="dynamic">
      <div class="title">
            <ul style="float:left;">
                  <li class="current"><a href="javascript:void(0)" title="我的好友">我的好友</a></li>
                  <li><a href="javascript:void(0)" title="我关注的">我关注的</a></li>
                  <li><a href="javascript:void(0)" title="关注我的">关注我的</a></li>
            </ul>
      </div>
      <div class="main_content">
            <div style="display:block;">
                  <ul>
                        <?php foreach($friend as $v){
                                    $tmp[]=($v[uid]==Yii::app()->user->id)?$v[fid]:$v[uid];
                              }
                              $data = array();
                              if(count($tmp)){
                                    $tmp = implode(',', $tmp);
                                    $twitters = Yii::app()->db->createCommand("select t.content as content ,t.dateline as dateline ,u.nickname,u.id from user_twitters t, users u where t.uid=u.id and t.uid in ($tmp) order by t.dateline DESC limit 20 ")->queryALL();
                                    // $feeds =  Yii::app()->db->createCommand("select t.link ,t.date,u.nickname from feed t, users u where t.uid=u.id and t.uid in ($tmp) order by t.date DESC limit 20")->queryALL();
                              }
                              

                        ?>
                        <?php if(count($data)):
                              foreach($data as $v):
                        ?>
                        <li><span><?php echo date('Y/n/j H:i',$v['dateline']);?></span><?php echo CHtml::link(CHtml::encode($v['nickname']), array('space/index','id'=>$v[id]),array('title'=>CHtml::encode($v['nickname'])));?>说：<?php echo CHtml::encode($v['content']);?></li>
                         <?php endforeach;
                         else:
                         ?>
                        <li><span>没有动态</span></li>
                        <?php endif;?>

                  </ul>
            </div>
            <div>
                  <ul>
                       <?php foreach($follower as $v){
                                    $tmpa[]=($v[uid]==Yii::app()->user->id)?$v[fid]:$v[ud];
                              }
                              $data = array();

                              if(count($tmpa)){
                                    $tmpa = implode(',', $tmpa);
                                    $twitters = Yii::app()->db->createCommand("select t.content as content ,t.dateline as dateline ,u.nickname ,u.id from user_twitters t, users u where t.uid=u.id and t.uid in ($tmpa) order by t.dateline DESC limit 20 ")->queryALL();
                                    // $feeds =  Yii::app()->db->createCommand("select t.link as content,t.date as dateline ,u.nickname from feed t, users u where t.uid=u.id and t.uid in ($tmpa) order by t.date DESC limit 20")->queryALL();
                              }
                              

                        ?>
                        <?php if(count($twitters)):
                              foreach($twitters as $v):
                        ?>
                        <li><span><?php echo date('Y/n/j H:i',$v['dateline']);?></span><?php echo CHtml::link(CHtml::encode($v['nickname']), array('space/index','id'=>$v[id]),array('title'=>CHtml::encode($v['nickname'])));?>说：<?php echo CHtml::encode($v['content']);?></li>
                         <?php endforeach;
                         else:
                         ?>
                        <li><span>没有动态</span></li>
                        <?php endif;?>

                  </ul>
            </div>
            <div>
                  <ul>
                       <?php foreach($follow as $v){
                                    $tmpb[]=($v[uid]==Yii::app()->user->id)?$v[fid]:$v[uid];
                              }
                              $data = array();

                              if(count($tmpb)){
                                    $tmpb = implode(',', $tmpb);
                                    $data = Yii::app()->db->createCommand("select t.content as content ,t.dateline as dateline ,u.nickname,u.id from user_twitters t, users u where t.uid=u.id and t.uid in ($tmpb) order by t.dateline DESC limit 20 ")->queryALL();
                                    // $feeds =  Yii::app()->db->createCommand("select t.link as content,t.date as dateline ,u.nickname from feed t, users u where t.uid=u.id and t.uid in ($tmpb) order by t.date DESC limit 20")->queryALL();
                              }
                              

                        ?>
                        <?php if(count($data)):
                              foreach($data as $v):
                        ?>
                        <li><span><?php echo date('Y/n/j H:i',$v['dateline']);?></span><?php echo CHtml::link(CHtml::encode($v['nickname']), array('space/index','id'=>$v[uid]),array('title'=>CHtml::encode($v['nickname'])));?>说：<?php echo CHtml::encode($v['content']);?></li>
                         <?php endforeach;
                         else:
                         ?>
                        <li><span>没有动态</span></li>
                        <?php endif;?>

                  </ul>
            </div>
      </div>
      <h2>查看更多</h2>
</div>
<div class="right_side">
      <div class="talk"> <span class="left">说：</span>
            <textarea id="talk_con" name="talk_con">我要去参加╳╳╳这个活动，有没有要一起去的？</textarea>
            <span class="talk_but">发送</span> </div>
            <div class="online_friends">
                  
                  <div class="pub_friend">
                        <h3><a href="?r=home/friend&b=1" title="我的好友">我的好友（<?php echo ($num=count($friend))?$num:0;?>）</a></h3>
                        <ul>
                              <?php if($num):
                              foreach($friend as $v):
                                    $frid = ($v[uid]==Yii::app()->user->id)?$v[fid]:$v[uid];?>
                              <li><a href="?r=space&id=<?php echo $frid;?>" title="<?php echo CHtml::encode($v[nickname]);?>"><img src="<?php echo Utils::getAvatar($v[avatar]);?>" width="43" height="43" alt="pic"/></a></li>
                              <?php endforeach;
                              else:
                                    echo "<li>无</li>";
                              endif;
                              ?>
                        </ul>
                  </div>
                  <div class="pub_friend">
                        <h3><a href="?r=home/friend&s=2&b=3" title="关注我的">关注我的（<?php echo ($num=count($follow))?$num:0;?>）</a></h3>
                        <ul>
                             <?php if($num):
                             foreach($follow as $v):
                              $frid = ($v[uid]==Yii::app()->user->id)?$v[fid]:$v[uid];?>
                        <li><a href="?r=space&id=<?php echo $frid;?>" title="<?php echo CHtml::encode($v[nickname]);?>"><img src="<?php echo Utils::getAvatar($v[avatar]);?>" width="43" height="43" alt="pic"/></a></li>
                        <?php endforeach;
                        else:
                              echo "<li>无</li>";
                        endif;
                        ?>
                  </ul>
            </div>
            <div class="pub_friend">
                  <h3><a href="?r=home/friend&s=1&b=2" title="我关注的">我关注的（<?php echo ($num=count($follower))?$num:0;?>）</a></h3>
                  <ul>
                       <?php if($num):
                       foreach($follower as $v):
                        $frid = ($v[uid]==Yii::app()->user->id)?$v[fid]:$v[uid];?>
                  <li><a href="?r=space&id=<?php echo $frid;?>" title="<?php echo CHtml::encode($v[nickname]);?>"><img src="<?php echo Utils::getAvatar($v[avatar]);?>" width="43" height="43" alt="pic"/></a></li>
                  <?php endforeach;
                  else:
                        echo "<li>无</li>";
                  endif;
                  ?>
            </ul>
      </div>
      <p><a href="?r=home/blist&b=4" title="黑名单管理">黑名单管理</a></p>
</div>
<script type="text/javascript">
$('.talk_but').click(function(){
     var val = $('#talk_con').val();
     $.post('?r=home/twitter',{content:val},
        function(data) { 
            data=$.parseJSON(data); 
            $('#topmsg').html(data.desc)
            $('#showmsg').show();
            showDialog();
            setTimeout(function(){$('#showmsg').hide();},1000);
        })
})
</script>